package com.mgl.movesprite;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.CameraScene;
import org.andengine.entity.scene.Scene;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import android.util.Log;

import com.mgl.movesprite.game.factory.GameObjectFactory;
import com.mgl.movesprite.game.factory.GameTextureManager;
import com.mgl.movesprite.game.model.Level;
import com.mgl.util.ButtonSprite;

public class PauseButton extends ButtonSprite {

	private boolean isPaused = false;
	private Scene scene = null;
	
	
	private Scene pauseScene = null;
	
	public PauseButton(float pX, float pY, ITextureRegion pTextureRegion,
			VertexBufferObjectManager pVertexBufferObjectManager,
			GameObjectFactory gameObjectFactory, Scene scene, Camera camera) {

		super(pX, pY, pTextureRegion, pVertexBufferObjectManager,
				gameObjectFactory);
		
		this.scene = scene;
		
		pauseScene = new CameraScene(camera);
		pauseScene.setBackgroundEnabled(false);
		
	}

	@Override
	public void update(float pSecondsElapsed, Level level) {

	}

	@Override
	public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
			final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
		
		  // Toggle pause or not                         
        switch(pSceneTouchEvent.getAction()) {
                case TouchEvent.ACTION_DOWN:
                        if(isPaused) {
                                isPaused = false;
                                scene.clearChildScene();
                                scene.setIgnoreUpdate(false);
                        }
                        else {
                                isPaused = true;
                                scene.setIgnoreUpdate(true);
                                scene.setChildScene(pauseScene, false, true, true);
                                Log.d("paused", "done");
                        }
                        break;
                case TouchEvent.ACTION_MOVE:
                        break;
                case TouchEvent.ACTION_UP:
                        break;
        }
        return true;
	}

}
